home *** CD-ROM | disk | FTP | other *** search
/ NeXTSTEP 3.1 (Developer) [x86] / NeXT Step 3.1 Intel dev.cdr.dmg / usr / sybase / include / sybdb.h next >
Encoding:
C/C++ Source or Header  |  1993-04-22  |  45.5 KB  |  1,436 lines

  1. /*
  2.  *    sybdb.h    62.3    7/5/90
  3.  *
  4.  *    Sybase DB-LIBRARY Version 4.0
  5.  *    Confidential Property of Sybase, Inc.
  6.  *    (c) Copyright Sybase, Inc. 1988, 1989
  7.  *    All rights reserved
  8.  *
  9.  *
  10.  * Use, duplication, or disclosure by the United States Government
  11.  * is subject to restrictions as set forth in subparagraph (c) (1) (ii)
  12.  * of the Rights in Technical Data and Computer Software clause
  13.  * at CFR 52.227-7013. Sybase, Inc. 6475 Christie Avenue, Emeryville,
  14.  * CA 94608.
  15.  *
  16.  */
  17.  
  18. /* temporarily undef ABS since there is one in sybdbtokens.h */
  19. #ifdef    ABS
  20. #undef    ABS
  21. #endif    /* ABS */
  22. #include    <sybdbtoken.h>
  23. #ifdef    ABS
  24. #undef    ABS
  25. #endif    /* ABS */
  26. #define    ABS(a)        ((a) > 0 ? (a) : -(a))
  27.  
  28. /*
  29. **  Status code for dbnextrow() and dbgetrow().
  30. **  Return of > 0 indicates ALTROW.
  31. **  FAIL is another possible return.
  32. */
  33. #define    MORE_ROWS    -1
  34. #define    NO_MORE_ROWS    -2
  35. #define    REG_ROW        MORE_ROWS
  36. #define    BUF_FULL    -3
  37.  
  38. /*
  39. **  Status code for dbresults(). Possible return values are
  40. **  SUCCEED, FAIL, and NO_MORE_RESULTS.
  41. */
  42. #define NO_MORE_RESULTS    2
  43.  
  44. /*
  45. **  Return code for message-handlers. Indicates whether or not the handler
  46. **  wants DB-LIBRARY to buffer the current Server message for later use
  47. **  by the program.
  48. */
  49. #define DBSAVE        1
  50. #define DBNOSAVE    0
  51.  
  52. #define DBNOERR        -1
  53.  
  54. /*
  55. ** Default size of row buffer.  This is what people get if they do
  56. ** a dbsetopt(dbproc, DBBUFFER, 0).
  57. */
  58. #define    DBBUFSIZE    1000
  59.  
  60. /* The size of a SYBTEXT timestamp, in bytes. This timestamp is not to be
  61.  * confused with a browse-mode timestamp.
  62.  */
  63. #define DBTXTSLEN    8
  64.  
  65. /* The size of a text-pointer, in bytes. */
  66. #if !VMS
  67. #define DBTXPLEN    ((DBTINYINT)16)
  68. #else
  69. #define DBTXPLEN    ((unsigned char)16)
  70. #endif
  71.  
  72. /*
  73. ** this is defined in the SQL Server server.h but it has alot of other 
  74. ** stuff that we don't want.
  75. */
  76. #define    MAXNAME    30
  77.  
  78. #include    <syblogin.h>
  79.  
  80. #define    DBMAXCHAR    256
  81. #define    DBMAXCOLNAME    30
  82. #define    DBMAXBYLIST    16
  83.  
  84. /* maximum printing lengths for fixed-length data */
  85. #define    PRINT4    11
  86. #define    PRINT2    6
  87. #define    PRINT1    3
  88. #define    PRFLT8    20
  89. #define    PRMONEY    24
  90. #define    PRBIT    1
  91. #define    PRDATETIME    20
  92. #define    PRLDATETIME    24    /* includes milliseconds */
  93.  
  94. /* SQL Server variable typedefs */
  95. typedef    unsigned short    DBUSMALLINT;    /* SQL Server 2 byte integer */
  96. typedef struct dbvarychar        /* Pascal-type string. */
  97. {
  98.     DBSMALLINT    len;        /* length of the character string */
  99.     DBCHAR        str[DBMAXCHAR];    /* string, with no NULL terminator */
  100. } DBVARYCHAR;
  101. typedef struct dbvarybin        /* Pascal-type binary array. */
  102. {
  103.     DBSMALLINT    len;        /* length of the binary array */
  104.     BYTE        array[DBMAXCHAR];/* the array itself. */
  105. } DBVARYBIN;
  106.  
  107. #define    TINYBIND    1
  108. #define    SMALLBIND    2
  109. #define    INTBIND        3
  110. #define    CHARBIND    4
  111. #define    TEXTBIND    5
  112. #define    BINARYBIND    6
  113. #define    ARRAYBIND    7
  114. #define    BITBIND        8
  115. #define    DATETIMEBIND    9
  116. #define    MONEYBIND    10
  117. #define    FLT8BIND    11
  118. #define    STRINGBIND    12
  119. #define    NTBSTRINGBIND    13
  120. #define VARYCHARBIND    14
  121. #define VARYBINBIND    15
  122. #if VOS
  123. #define    FIXEDBIND    16            /*kvk589*/
  124. #define PACKEDBIND    17            /*kvk589*/
  125. #define MAXBIND        PACKEDBIND        /*kvk589*/
  126. #else
  127. #define MAXBIND        VARYBINBIND
  128. #endif
  129.  
  130. /*
  131. ** From pss.h SQL Server structure.
  132. */
  133. /* Donepacket status bit defs go here */
  134. # define DONE_CONT    (DBUSMALLINT) 0x1    
  135. # define DONE_ERROR    (DBUSMALLINT) 0x2
  136. # define DONE_INXACT    (DBUSMALLINT) 0x4
  137. # define DONE_PROC    (DBUSMALLINT) 0x8
  138. # define DONE_COUNT    (DBUSMALLINT) 0x10
  139. # define DONE_ATTN    (DBUSMALLINT) 0x20
  140.  
  141. /*
  142. **    OFFSETS DEFINITIONS
  143. **
  144. **    These are a subset of the token values for offset information.
  145. **    These defines come from y.tab.h
  146. **
  147. */
  148. #define _SELECT 365
  149. #define _EXECUTE 330
  150. #define _FROM 335
  151. #define _ORDER 357
  152. #define _COMPUTE 313
  153. #define _TABLE 371
  154. #define _PROCEDURE 362
  155. #define _STATEMENT 459
  156. #define _PARAM 452
  157. /* end y.tab.h */
  158.  
  159. /*
  160. ** HOSTSERVER.h - structures and defines for communicating with server
  161. **
  162. */
  163.  
  164. /*
  165. ** Data structure used by both send and recv
  166. */
  167. typedef struct servbuf
  168. {
  169.     BYTE    *serv_sbuf;    /* send: start of send buffer */
  170.     BYTE    *serv_snb;    /* send: next place in buffer */
  171.     int    serv_sleft;    /* send: room left in send buffer */
  172.     int    serv_sbsize;    /* send: buffer size */
  173.     int    serv_snum;    /* send # for network */
  174.     int    serv_sstat;    /* send: status bits */
  175.     BYTE    *serv_rbuf;    /* recv: start of recv buffer */
  176.     BYTE    *serv_rnb;    /* recv: next place in buffer */
  177.     int    serv_rleft;    /* recv: room left in recv buffer */
  178.     int    serv_rbsize;    /* recv: buffer size */
  179.     int    serv_rnum;    /* recv # for network */
  180.     int    serv_rstat;    /* recv: status bits */
  181.     int    serv_commtype;    /* communications type (tcp, etc.) */
  182.     RETCODE    (*serv_attn)(); /* network-dependent routine to send
  183.                  * an ATTN packet to the SQL Server.
  184.                  */
  185.     DBINT    (*serv_read)();    /* network-dependent routine to read
  186.                  * a byte stream from the SQL Server.
  187.                  */
  188.     RETCODE    (*serv_read_a)();/* async version of serv_read(). */
  189.     DBINT    (*serv_writ)();    /* network-dependent routine to write
  190.                  * a byte stream to the SQL Server.
  191.                  */
  192.     RETCODE    (*serv_clos)();    /* network-dependent routine to close
  193.                  * a connection to the SQL Server.
  194.                  */
  195. } SERVBUF;
  196.  
  197.  
  198. /*
  199. **  DBSTRING - This structure is just used for stringing text or parameters
  200. **    together.
  201. */
  202. struct dbstring
  203. {
  204.     BYTE     *strtext;    /* actual byte string */
  205.     DBINT    strtotlen;    /* allocated length of the byte string */
  206.     struct dbstring    *strnext;
  207. };
  208. typedef struct dbstring    DBSTRING;
  209.  
  210. /*
  211. **    DBROWDATA - This structure is used to hold the actual data that
  212. **    comes back for every column in every row. The DBPROCESS structure
  213. **    points to a linked-list of DBROW structures. Each DBROW strcture points
  214. **    to an array of DBROWDATA structures. Since every DBROWDATA structure
  215. **    contains pointers to separately allocated buffers, the members of
  216. **    each array are linked together in a singly-linked list, to facilitate
  217. **    the operation of simple row-freeing routines.
  218. */
  219. struct dbrowdata
  220. {
  221.     BYTE         *data;        /* actual data for this column in this
  222.                      * row
  223.                      */
  224.     DBINT        datlen;        /* length, in bytes, of this data */
  225.     DBBINARY    dattxptr[DBTXPLEN];/* This data's text-ptr, if it's of
  226.                      * type SYBTEXT.
  227.                      */
  228.     DBTINYINT    dattxplen;    /* Length, in bytes, of the text-ptr. */
  229.     DBBINARY    dattxts[DBTXTSLEN];/* The text-timestamp of this text
  230.                      * value.
  231.                      */
  232.     DBTINYINT    dattxtslen;    /* Length, in bytes, of the
  233.                      * text-timestamp.
  234.                      */
  235.     struct dbrowdata    *datnext;
  236. };
  237. typedef struct dbrowdata    DBROWDATA;
  238.  
  239. /*
  240. **  BINDREC - This is the structure used to store information about
  241. **    which columns should be bound to which programming variables
  242. */
  243. struct    bindrec
  244. {
  245.     BYTE        *bindvar;    /* ptr to program variable */
  246.     DBINT        bindlen;    /* length of program variable */
  247.     DBINT        (*bindproc)();    /* procedure to use for data copy. */
  248.     DBINT        *bindnullind;    /* IBM-type indicator variable. */
  249. };
  250. typedef struct bindrec    BINDREC;
  251.  
  252. /*
  253. ** NULLBIND - This structure is attached to the DBPROCESS and is used
  254. **    to determine what to bind when bind values are NULL.
  255. */
  256. struct    nullbind
  257. {
  258.     DBBIT        nullbit;
  259.     DBTINYINT    nulltiny;
  260.     DBSMALLINT    nullsmall;
  261.     DBINT        nullint;
  262.     DBCHAR        *nullchar;
  263.     DBINT        nulllchar;    /* length of char string */
  264.     DBBINARY    *nullbinary;
  265.     DBINT        nulllbinary;    /* length of binary string */
  266.     DBDATETIME    nulldatetime;
  267.     DBMONEY        nullmoney;
  268.     DBFLT8        nullflt8;
  269.     DBCHAR        *nullstring;
  270.     DBCHAR        *nullntbstring;
  271.     DBVARYCHAR    nullvarychar;
  272.     DBVARYBIN    nullvarybin;
  273. };
  274. typedef struct nullbind    NULLBIND;
  275.  
  276. /*
  277. **  DBCOLINFO - This structure contains the format information about a column.
  278. **    There is a linked list of DBCOLINFO structures in the DBPROCESS
  279. **    structure.  There is one DBCOLINFO structure for each column in the
  280. **    target list of the current command.  Format information for
  281. **    alternate rows, like compute, is kept in the DBALTHEAD and
  282. **    DBALTINFO structures.
  283. */
  284. struct dbcolinfo
  285. {
  286.     char    colname[DBMAXCOLNAME+1];/* column name */
  287.     BYTE    coltype;        /* column type */
  288.     DBINT    coludtype;        /* user-defined type */
  289.     DBINT    collen;            /* max length of column */
  290.     DBINT    colprlen;        /* max printing length of column */
  291.     char    *colcontrol;        /* control format, if any */
  292.     struct bindrec    colbind;    /* binding info, if any */
  293.     int    coltable;        /* for browse mode: which table
  294.                      * did this column come from?
  295.                      */
  296.     BYTE        colstatus;    /* for browse mode: what kind of column
  297.                      * is this?
  298.                      */
  299.     char    colorigname[DBMAXCOLNAME+1];/* for browse mode: what is the name
  300.                      * of the table column that provided
  301.                      * this select-list member?
  302.                      */
  303.     char    *coltxobjname;        /* the SQL Server always returns the
  304.                      * qualified object-name for TEXT
  305.                      * columns.
  306.                      */
  307.     struct dbcolinfo    *colnext;    /* next column */
  308. };
  309. typedef    struct dbcolinfo    DBCOLINFO;
  310.  
  311. /*
  312. **  DBTABNAME - This structure contains information about the tables which
  313. **    were used to produce the current set of results. The SQL Server only
  314. **    provides this info for queries that are executed in "browse mode".
  315. **
  316. **    There is a linked list of DBTABNAME structures in the DBPROCESS
  317. **    structure.  There is one DBTABNAME structure for each table used to
  318. **    produce the target list of the current command.
  319. **
  320. **    If this query was executed without "browse mode", then this list will
  321. **    have no members.
  322. */
  323. struct dbtabname
  324. {
  325.     char            tabname[MAXNAME+1];    /* column name */
  326.     struct dbtabname    *tabnext;        /* next column */
  327. };
  328. typedef    struct dbtabname    DBTABNAME;
  329.  
  330. /*
  331. **  DBRETVAL - This structure contains any data which was returned as a function
  332. **    value by the last command. Currently, "browse-mode" updates are the only
  333. **    commands which return function values.
  334. **
  335. **    There is a linked list of DBRETVAL structures in the DBPROCESS
  336. **    structure.  There is one DBRETVAL structure for each function value
  337. **    returned by the current command.
  338. **
  339. **    If this command returned no function value, this list will
  340. **    have no members.
  341. */
  342. struct dbretval
  343. {
  344.     char        retname[MAXNAME+1];    /* value name */
  345.     BYTE        retvalstat;        /* status byte */
  346.     DBINT        retusertype;        /* user type */
  347.     BYTE        rettype;        /* value type */
  348.     DBINT        retmaxlen;        /* max value length (ignored) */
  349.     DBINT        retlen;            /* value length */
  350.     BYTE        *retdata;        /* the return-value itself. */
  351.     struct dbretval    *retnext;        /* next return-value */
  352. };
  353. typedef    struct dbretval    DBRETVAL;
  354.  
  355. /*
  356. **  DBALTHEAD - This structure contains information for ALT rows.  ALT
  357. **    rows are COMPUTE results.  There is one DBALTHEAD for each COMPUTE
  358. **    statement.  All the COMPUTE operators in a particular COMPUTE statement
  359. **    must have the same bylist -- this is enforced by the SQL Server.
  360. **    Off of each DBALTHEAD is a linked list of DBALTINFO structures that
  361. **    describe the format for each particular COMPUTE operation in the
  362. **    COMPUTE.
  363. */
  364. struct    dbalthead
  365. {
  366.     DBUSMALLINT    althid;        /* id for this COMPUTE statement */
  367.     BYTE    althalts;    /* number of DBALTINFO structures in althlist */
  368.     BYTE    althsizeby;    /* number of elements in the bylist */
  369.     BYTE    althbylist[DBMAXBYLIST];    /* colids of bylist elements */
  370.     struct dbaltinfo    *althlist;    /* linked list of DBALTINFOs */
  371.     struct dbprlist        *althprlist;    /* order print list for aops */
  372.     struct dbalthead    *althnext;    /* next dbalthead */
  373. };
  374. typedef struct dbalthead    DBALTHEAD;
  375.  
  376. /*
  377. **  DBPRLIST - This structure is used to create an 'ordered' printing list
  378. **    for computes.  For example a compute might be:
  379. **        compute sum(col1), avg(col2), sum(col2), avg(col3), avg(col1)
  380. **    For printing, it would be nice to have a list that pointed to the
  381. **    right DBALTINFO structures like this:
  382. **        sum(col1)-->sum(col2)
  383. **          |
  384. **         \|/
  385. **        avg(col1)-->avg(col2)-->avg(col3)
  386. **    It is used by the praltrow function that dbprrow uses but the
  387. **    information could be used by any DBLIB client.
  388. */
  389. struct    dbprlist
  390. {
  391.     DBROWDATA    *prdata;    /* actual data for the compute */
  392.     struct dbaltinfo    *prtarget;    /* related ALTINFO struct */
  393.     struct dbprlist        *prright;    /* next aop in compute */
  394.     struct dbprlist        *prdown;    /* next compute in query */
  395. };
  396. typedef struct dbprlist    DBPRLIST;
  397.  
  398. /*
  399. **  DBALTINFO - This structure contains the format information about
  400. **    alternate rows.  Compute clauses produce alternate rows of data,
  401. **    interspersed with the regular data rows returned by the dataserver.
  402. **    There is a linked list of DBALTHEAD structures in the DBPROCESS
  403. **    structure.  There is one DBALTHEAD structure for each possible
  404. **    type of alternate row of the current command.  Format information for
  405. **    regular data rows is kept in the DBCOLINFO structure.
  406. */
  407. struct dbaltinfo
  408. {
  409.     char    *altname;    /* null terminated string to alt header */
  410.     BYTE    alttoken;    /* type of alternate information */
  411.     BYTE    altcolid;    /* which target list member referenced */
  412.     BYTE    alttype;    /* column type */
  413.     DBINT    altudtype;    /* user-defined type */
  414.     DBINT    altlen;        /* max length of column */
  415.     DBINT    altprlen;    /* printing length of data */
  416.     char    *altcontrol;        /* control format, if any */
  417.     struct dbprlist    *altprlist;    /* ptr to ordered printing list */
  418.     struct bindrec    altbind;    /* binding info, if any */
  419.     struct dbaltinfo    *altnext;    /* next column */
  420. };
  421. typedef    struct dbaltinfo    DBALTINFO;
  422.  
  423. /*
  424. **  DBROW - This structure is used to store the actual row and alternate row
  425. **    data returned by the dataserver.  The member of the DBPROCESS structure 
  426. **    called dbfirstdata stores the doubly-linked list of rows.  If buffering
  427. **    is off, only one row is stored.  The rows are stored in the order that
  428. **    they are received from the server.
  429. */
  430. struct dbrow
  431. {
  432.     DBINT        rowid;        /* this is the returned row number */
  433.     DBUSMALLINT    rowaltid;    /* for ALT rows, this is
  434.                      * DBALTINFO.altid
  435.                      */
  436.     DBROWDATA    *rowdata;    /* actual data */
  437.     DBBOOL                rowhasnull;    /* are there any NULLS in this row of
  438.                      * data?
  439.                      */
  440.     struct dbrow    *rowprev;    /* previous row if buffering on */
  441.     struct dbrow    *rownext;    /* next row if buffering on */
  442.     SECLAB         dbseclab;    /* security label */
  443.     unsigned long    dbcrc;        /* row crc (security only) */
  444. };
  445. typedef struct dbrow    DBROW;
  446.     
  447. /*
  448. **  DBINFO - This structure is used to store information and error messages
  449. **    returned by the dataserver.
  450. **
  451. **    NOTE - This structure is used by APT.
  452. **        Adding or deleting structure members should be done with
  453. **        care.
  454. */
  455. struct dbinfo
  456. {
  457.     DBINT        infonum;    /* error or info number */
  458.     DBTINYINT    infostate;    /* error state number */
  459.     DBTINYINT    infoclass;    /* info class or error severity */
  460.     char        *infotext;    /* null terminated message */
  461.     char        *infoservname;    /* null terminated Server-name */
  462.     char        *infoprocname;    /* null terminated procedure-name */
  463.     DBUSMALLINT    infolinenum;    /* stored-procedure line-number */
  464.     struct dbinfo    *infonext;
  465. };
  466. typedef struct dbinfo    DBINFO;
  467.  
  468. /*
  469. **  Options - both for the dataserver and DBLIB
  470. **    As additional options are added, they should be added here and in
  471. **    the Dboptdict array.
  472. */
  473.  
  474. /*
  475. ** dataserver options are defined in pss.h
  476. ** dataserver options and their index into the Dboptdict array
  477. ** Dboptdict is defined in options.c
  478. */
  479. #define DBPARSEONLY    0
  480. #define DBESTIMATE    1    
  481. #define DBSHOWPLAN    2
  482. #define DBNOEXEC    3
  483. #define DBARITHIGNORE    4
  484. #define DBNOCOUNT    5
  485. #define DBARITHABORT    6
  486. #define DBTEXTLIMIT    7
  487. #define DBBROWSE    8
  488. #define DBOFFSET    9
  489. #define DBSTAT        10
  490. #define DBERRLVL    11
  491. #define DBCONFIRM    12
  492. #define DBSTORPROCID    13
  493. #define DBBUFFER    14
  494. #define DBNOAUTOFREE    15
  495. #define DBROWCOUNT    16
  496. #define DBTEXTSIZE    17
  497.  
  498. #define    OFF        0
  499. #define    ON        1
  500.  
  501. /* RETCODES for option routines */
  502. #define    NOSUCHOPTION    2
  503.  
  504. /*
  505. **  DBOPTION - This structure is used to store the current dataserver and
  506. **    dblib options.
  507. */
  508. struct dboption
  509. {
  510.     char    *opttext;
  511.     DBSTRING    *optparam;    /* param to the option */
  512.     DBUSMALLINT    optstatus;    /* status of option */
  513.     DBBOOL            optactive;    /* is this structure active (being used?) */
  514.     struct dboption    *optnext;    /* for different versions of an option */
  515. };
  516. typedef struct dboption    DBOPTION;
  517.  
  518.  
  519. /*
  520. ** These are the offset types recognized by the SQL Server
  521. ** They are contained in the SQL Server header pss.h.  The _defines
  522. ** come from y.tab.h.
  523. */
  524. #define OFF_SELECT    (DBUSMALLINT) _SELECT
  525. #define OFF_EXEC    (DBUSMALLINT) _EXECUTE
  526. #define OFF_FROM    (DBUSMALLINT) _FROM
  527. #define OFF_ORDER    (DBUSMALLINT) _ORDER
  528. #define OFF_COMPUTE    (DBUSMALLINT) _COMPUTE
  529. #define OFF_TABLE    (DBUSMALLINT) _TABLE
  530. #define OFF_PROCEDURE    (DBUSMALLINT) _PROCEDURE
  531. #define OFF_STATEMENT    (DBUSMALLINT) _STATEMENT
  532. #define OFF_PARAM    (DBUSMALLINT) _PARAM
  533.  
  534. /*
  535. **  DBOFF - This structure is used to store text offset information.
  536. **    This information is used to send back to the dataserver new
  537. **    control formats.  
  538. */
  539. struct dboff
  540. {
  541.     DBUSMALLINT    offtype;    /* type of offset */
  542.     DBUSMALLINT    offset;        /* actual offset */
  543.     struct dboff    *offnext;
  544. };
  545. typedef struct dboff    DBOFF;
  546.  
  547. /*
  548. **  DBDONE - This structure is just the dataserver done packet.
  549. **    It has information about the completion of a command.
  550. */
  551. struct dbdone
  552. {
  553.     DBUSMALLINT    donestatus;    /* done status bits */
  554.     DBUSMALLINT    doneinfo;    /* command specific info */
  555.     DBINT        donecount;    /* done count -- rows for example */
  556. };
  557. typedef struct dbdone    DBDONE;
  558.  
  559. /* Status bits for DBPROCESS dbstatus */
  560. #define    READROW        (DBUSMALLINT) 0x2
  561. #define    INSPROC        (DBUSMALLINT) 0x4
  562. #define    EXECDONE    (DBUSMALLINT) 0x8
  563. #define    NEWDB        (DBUSMALLINT) 0x10
  564.  
  565. /* Possible flags for dbback_compatible(). Currently the only
  566. ** one is DBEXTRARESULTS.
  567. */
  568. #define DBEXTRARESULTS  (DBUSMALLINT) 0x1
  569.  
  570.  
  571. /* Bulk-copy information -- */
  572.  
  573. #define    PERIOD    '.'    /* the separator... */
  574.  
  575. #define    STATNULL    (BYTE) 0x08
  576. #define IN        (BYTE) 1 /* TEMPORARY - for backward compatibility. */
  577. #define    OUT        (BYTE) 2 /* TEMPORARY - for backward compatibility. */
  578. #define DB_IN        (BYTE) 1
  579. #define    DB_OUT        (BYTE) 2
  580. #define BCPNAMELEN    255
  581. #define DEFABORT    10        /* # of errors before we give up */
  582. #define    ERRFILE        "bcp.error"    /* default error file name */
  583.  
  584. /* BCP macros: */
  585. #define BCP_SETL(a,b)        dbsetlbool((a), (b), DBSETBCP)
  586.  
  587. /* The fields for calls to bcpcontrol. */
  588. #define    BCPMAXERRS    1
  589. #define    BCPFIRST    2
  590. #define    BCPLAST        3
  591. #define    BCPBATCH    4
  592. #define    BCPERRFILE    5    /* TEMPORARY - for backward compatibility. */
  593.  
  594. /* This macro is used by the Non-C interfaces to BCP-Library: */
  595. #define BCP_HOSTTYPE(a, b)    (((a)->db_bcpdesc->bd_hostdesc + (b - 1))->htype)
  596.  
  597. typedef    struct    bcpparsetable
  598. {
  599.     char    dbname[MAXNAME+1];
  600.     char    ownername[MAXNAME+1];
  601.     char    tabname[MAXNAME+1];
  602. } BCPPARSETABLE;
  603.  
  604. /*
  605. **  BCPCOLDESC
  606. **    This is the basic unit of information used for bulkcopy.
  607. **    All the bulkcopy routines that talk with the SQL Server
  608. **    routines pass an array of these.
  609. */
  610. typedef struct    bcpcoldesc
  611. {
  612.     BYTE    *cd_dvalue;        /* current value to be inserted */
  613.     BYTE    *cd_defvalue;        /* default value to be inserted */
  614.     DBINT    cd_dlen;        /* current length to be inserted */
  615.     DBINT    cd_deflen;        /* length of default to be inserted */
  616.     DBINT    cd_colen;        /* max length allowed in column */
  617.     short    cd_coloff;        /* column offset in row */
  618.     BYTE    cd_colid;        /* id of column */
  619.     BYTE    cd_type;        /* storage type of column */
  620.     BYTE    cd_status;        /* status bits */
  621.     DBBOOL            cd_nullok;        /* is a NULL ok here? */
  622.     char    cd_name[MAXNAME+1];    /* column name */
  623.     DBBOOL            cd_moretext;        /* Is this text to be sent via bcp__moretext? */
  624.     long    cd_textpos;        /* file-position of a long TEXT or IMAGE */
  625. } BCPCOLDESC;
  626.  
  627. /*
  628. **  BCPROWDESC
  629. **    This is the basic unit of information used for bulkcopy.
  630. **    All the bulkcopy routines that talk with the SQL Server
  631. **    routines pass it.
  632. */
  633. typedef struct bcprowdesc
  634. {
  635.     BCPCOLDESC    *rd_coldesc;    /* ptr to base address of COLDESC
  636.                      * array
  637.                      */
  638.     short        rd_colcount;    /* number of columns in COLDESC */
  639.     short        rd_minlen;    /* minimum length of a row */
  640.     short        rd_maxlen;    /* maximum length of a row */
  641. } BCPROWDESC;
  642.  
  643. /*
  644. ** BCPHOSTDESC
  645. **    This is the structure that has information about the type and
  646. **    format of the input or output data.  An array of these is used
  647. **    to read/write data to or from the host.
  648. */
  649. typedef struct    bcphostdesc
  650. {
  651.     BCPCOLDESC    *h_tabcol; /* which table column we are referring to */
  652.     int    h_tabcolnum;    /* which table column we are referring to */
  653.     DBINT    (*hconvert)();    /* conversion function, if applicable */
  654.     BYTE    htype;        /* host data type for this column */
  655.     DBINT    hcollen;    /* max length of hostfile column */
  656.     BYTE    *hdata;        /* host-format data for this column */
  657.     DBINT    hdatlen;    /* length of actual hostfile data */
  658.     int    hprefixlen;    /* length of length-prefix for this column */
  659.     BYTE    *hterm;        /* terminator for this column, if applicable */
  660.     int    htermlen;    /* length of terminator for this column */
  661.     DBBOOL            hmoretext;    /* Is this text to be sent via bcp__moretext? */
  662.     long    htextpos;    /* file-position of a long TEXT or IMAGE */
  663. } BCPHOSTDESC;
  664.  
  665. /* This structure contains information about any partially-sent TEXT or IMAGE
  666.  * values, which are still to be sent by bcp_moretext().
  667.  */
  668. typedef struct bcptextrec
  669. {
  670.     DBINT        len;
  671.     BYTE        *val;
  672.     BYTE        type;
  673.     DBSMALLINT    rowoffset;
  674.     BYTE        coloffset;
  675. } BCPTEXTREC;
  676.  
  677. /*
  678. **  BCPDESC
  679. **    This structure is used to pass the information contained in the
  680. **    Bulk Copy property sheet around (if in the form version), or 
  681. **    information typed in by the user (in dblib/stand alone version).
  682. **    In the form version, this information comes from the main form, while
  683. **    in the stand alone version this comes from the command line.
  684. */
  685. typedef struct    bcpdesc
  686. {
  687.     BCPROWDESC    *bd_rowdesc;        /* the associated rowdesc */
  688.     BCPHOSTDESC    *bd_hostdesc;        /* ptr to base address of
  689.                         ** BCPHOSTDESC array */
  690.     int        bd_hcolcount;        /* number of (cols) BCPHOSTDESC 
  691.                         ** structs */
  692.     BCPPARSETABLE    *bd_ptable;        /* ptr to tbl name components */
  693.     char        bd_table[(3 * MAXNAME) + 3]; /* full table name */
  694.     char        bd_filename[BCPNAMELEN+1];/* host filename */
  695.     BYTE        bd_direction;        /* in/out */
  696.     char        *bd_errfilename;    /* host err file name */
  697.     BYTE        *bd_errfile;        /* host err file pointer */
  698.     DBINT        bd_abort;        /* # of errors allowable */
  699.     DBINT        bd_firstrow;        /* begin copy at this row */
  700.     DBINT        bd_lastrow;        /* end copy at this row */
  701.     DBINT        bd_batch;        /* # of rows per batch */
  702.     int        bd_textcount;        /* # of text-columns in the
  703.                          * current row.
  704.                          */
  705.     int        bd_textcol;        /* # of the text-column now
  706.                          * being sent by bcp_moretext().
  707.                          * Starts at zero.
  708.                          */
  709.     DBINT        bd_textbytes;        /* # of bytes already sent of
  710.                          * the current bcp_moretext()
  711.                          * column.
  712.                          */
  713.     BCPTEXTREC    *bd_textarray;
  714. } BCPDESC;
  715.  
  716.  
  717. /*
  718. **  DBPROCESS - This is the basic DBLIB structure. It contains the command
  719. **    sent to the dataserver as well as the results of the command.
  720. **    It also includes any error or information messages, including the
  721. **    done packet, returned by the dataserver.  If buffering is turned on,
  722. **    this structure also stores the data rows.
  723. */
  724. struct    dbprocess
  725. {
  726.     struct servbuf    *dbfile;    /* dataserver connection */
  727.     DBUSMALLINT    dbstatus;    /* status field for dbprocess */
  728.     BYTE        dbtoken;    /* current dataserver token */
  729.     DBSTRING    *dbcmdbuf;    /* command buffer */
  730.     int        dbcurcmd;    /* number of the current cmd results */
  731.     DBINT        dbprocid;    /* procid, if any, of the current cmd */
  732.     DBCOLINFO    *dbcols;    /* linked list of column information */
  733.     DBALTHEAD    *dbalts;    /* linked list of alt column info */
  734.     DBROW        *dbfirstdata;    /* doubly linked list of returned row
  735.                      * data
  736.                      */
  737.     DBROW        *dbcurdata;    /* current row in dbfirstdata */
  738.     DBROW        *dblastdata;    /* last row in dbfirstdata, usually
  739.                      * dbcurdata
  740.                      */
  741.     DBOFF        *dboffsets;    /* list of offsets and controls in
  742.                      * dbcmdbuf
  743.                      */
  744.     int        dboffadjust;    /* adjustment factor for offsets */
  745.     DBSMALLINT    dbcuroffset;    /* active offset for results */
  746.     DBOPTION    *dbopts;
  747.     DBSTRING    *dboptcmd;    /* option string to send to server */
  748.     DBINFO        *dbmsgs;    /* linked list of info and error
  749.                      * messages
  750.                      */
  751.     DBINFO        *dbcurmsg;    /* last message read by dbgetmsg() */
  752.     DBDONE        dbdone;        /* done information */
  753.     char        dbcurdb[MAXNAME+1];    /* the name of the current
  754.                          * database
  755.                          */
  756.     int        (*(*dbbusy)())(); /* function to call when waiting on
  757.                        * dataserver
  758.                        */
  759.     void        (*dbidle)();    /* function to call when waiting on
  760.                      * dataserver
  761.                      */
  762.     int        (*dbchkintr)();    /* user's function to call to check for
  763.                      * queued interrupts
  764.                      */
  765.     int        (*dbhndlintr)();/* user's interrupt handler */
  766.     int        dbbufsize;    /* the size of the row buffer, if
  767.                      * enabled
  768.                      */
  769.     NULLBIND    dbnullbind;    /* what to bind for nulls */
  770.     int        dbsticky;    /* sticky flags like attn */
  771.     int        dbnumorders;    /* number of columns in the query's
  772.                      * "order by" clause.
  773.                      */
  774.     int        *dbordercols;    /* array of the column numbers found in
  775.                      * the query's "order by" clause.
  776.                      */
  777.     DBBOOL                dbavail;    /* is this dbproc available for general
  778.                      * use?
  779.                      */
  780.     int        dbftosnum;    /* this id is used when recording the
  781.                      * frontend-to-Server SQL traffic of
  782.                      * this DBPROCESS.
  783.                      */
  784.     DBBOOL                dbdead;        /* TRUE if this DBPROCESS has become
  785.                      * useless, usually due to a fatal
  786.                      * Server error, or a communications
  787.                      * failure.
  788.                      */
  789.     DBBOOL                dbenabled;    /* TRUE if this DBPROCESS is allowed to
  790.                      * be used in DB-LIBRARY functions. The
  791.                      * user may set this flag FALSE,
  792.                      * possibly within an error handler, if
  793.                      * execution of further commands would
  794.                      * just cause further errors.
  795.                      * DB-LIBRARY initially sets this flag
  796.                      * TRUE. The user may set and re-set
  797.                      * this flag at will.
  798.                      */
  799.     DBBOOL                dbsqlsent;    /* TRUE if the SQL in the command
  800.                      * buffer has already been sent to
  801.                      * the SQL Server.
  802.                      */
  803.     DBTABNAME    *dbtabnames;    /* linked-list of table-name
  804.                      * information used by "browse mode".
  805.                      */
  806.     DBINT        dbspid;        /* The Server process-id of this
  807.                      * DBPROCESS. It's returned in the
  808.                      * row-count field of the done-packet
  809.                      * which signifies a successful login.
  810.                      */
  811.     DBRETVAL    *dbretvals;    /* linked-list of function
  812.                      * return-values.
  813.                      */
  814.     BCPDESC        *db_bcpdesc;    /* A structure containing bulk-copy
  815.                      * information.
  816.                      */
  817.     DBBOOL                dbtransbegun;    /* Indicates that a text data transfer
  818.                      * is under way.
  819.                      */
  820.     DBINT        dbbytesleft;    /* This is a countdown variable, used
  821.                      * to track the number of bytes which
  822.                      * are still to be sent as part of
  823.                      * a dbwritetext() command.
  824.                      */
  825.     DBINT        dbretstat;    /* This is the return-status from
  826.                      * a stored procedure.
  827.                      */
  828.     DBBOOL                dbhasretstat;    /* Is the return-status valid? */
  829.     DBINT        dbtextlimit;    /* This is the longest text-column
  830.                      * that this dbproc will accept
  831.                      * from the Server. Any additional
  832.                      * bytes will be discarded.
  833.                      * If 0, then there's no limit.
  834.                      */
  835.     BYTE        *dbuserdata;    /* A pointer to any data that the
  836.                      * the user wishes to associate with
  837.                      * this DBPROCESS.
  838.                      */
  839.     DBINT        dbloginfailed;    /* The number of the Server message
  840.                      * which describes the reason for
  841.                      * this failed login.
  842.                      */
  843.     char        dblogin_node[MAXNAME + 1];
  844.                     /* The node that the Companion
  845.                      * Server's redirector has
  846.                      * recommended to us.
  847.                      */
  848.     int        dbcolcount;    /* The number of regular columns
  849.                      * in the current set of results.
  850.                      */
  851.  
  852.     DBBOOL        db_oldtds;    /* TRUE if the TDS version is older
  853.                      * than 4.0.
  854.                      */
  855.     int        db_tdsversion;    /* tds version for this dbproc. */
  856. #if VMS
  857.     int        db_event_mask;    /* a mask used to determine what
  858.                     ** event has happened in the front-
  859.                     ** end i/o routines.
  860.                     */
  861.     long        db_event_flag;    /* the number of the event flag used
  862.                     ** to check for timeout, interrupt 
  863.                     ** (control_c) or i/o completion.
  864.                     */
  865.     short        db_io_channel;    /* channel assigned to sys$command
  866.                     ** of the controlling process.
  867.                     */
  868.     short        r_iosb[4];    /* I/O status for read */
  869.     short        w_iosb[4];    /* I/O status for write */                
  870. #endif /* VMS */
  871.  
  872.     struct dbprocess    *dbnext;/* DBPROCESSes are kept track of
  873.                      * in a big linked-list.
  874.                      */
  875. };
  876. typedef struct dbprocess    DBPROCESS;
  877.  
  878. #define    DBTDS_2_0        1
  879. #define    DBTDS_3_4        2
  880. #define    DBTDS_4_0        3
  881.  
  882.  
  883. /*
  884. **  Various macros used to extract information from the DBPROCESS structure
  885. */
  886. #define    DBTDS(a)    ((a)->db_tdsversion)
  887. #define    DBCURCMD(a)    ((a)->dbcurcmd)
  888. #define    DBCURROW(a)    ((a)->dbcurdata == (DBROW *) NULL ? ((DBINT)0): (a)->dbcurdata->rowid)
  889. #define    DBFIRSTROW(a)    ((a)->dbfirstdata == (DBROW *) NULL ? ((DBINT)0): (a)->dbfirstdata->rowid)
  890. #define    DBLASTROW(a)    ((a)->dblastdata == (DBROW *) NULL ? ((DBINT)0): (a)->dblastdata->rowid)
  891. #define    DBROWTYPE(a)    ((a)->dbcurdata == (DBROW *) NULL ? (DBINT)NO_MORE_ROWS: \
  892.     ((a)->dbcurdata->rowaltid == 0 ? (DBINT)REG_ROW: (a)->dbcurdata->rowaltid))
  893. #define    DBMORECMDS(a)    ((a)->dbdone.donestatus & DONE_CONT ? SUCCEED: FAIL)
  894. #define    DONECONTINUE(a)    ((a)->dbdone.donestatus & DONE_CONT ? SUCCEED: FAIL)
  895. #define    DBCOUNT(a)    ((a)->dbdone.donestatus & DONE_COUNT ? (a)->dbdone.donecount : ((DBINT)(-1)))
  896. #define    DBCMDROW(x)    ((x)->dbcols == NULL ? FAIL: SUCCEED)
  897. #define    DBROWS(x)    (((x)->dbstatus & READROW) ? SUCCEED: FAIL)
  898. #define DBNUMORDERS(a)    ((a)->dbnumorders)
  899. #define DBBUFFULL(a)    (DBLASTROW(a) - DBFIRSTROW(a) + 1 >= (a)->dbbufsize ? \
  900.     TRUE : FALSE)
  901. #define DBMOREROWS(a)    (((a)->dbtoken == SYBROW) || ((a)->dbtoken == SYBALTROW) ? \
  902.     TRUE : FALSE)
  903. #define DBISAVAIL(a)    (((a)->dbavail) ? TRUE : FALSE)
  904. #define DBGETTIMEOUT(a)    (DbTimeout)
  905. #define DBGETTIME()    (DbTimeout)
  906. #define DBDEAD(a)    ((a)->dbdead)
  907. #define DBIORDESC(a)    ((a)->dbfile->serv_rnum)
  908. #define DBIOWDESC(a)    ((a)->dbfile->serv_snum)
  909. #define DBRBUF(a)    (((a)->dbfile->serv_rleft || (!((a)->dbsticky & (DBUSMALLINT) 0x1))) ? ((DBBOOL)TRUE) : ((DBBOOL)FALSE))
  910.  
  911. #if (VMS)
  912. #define DBZEROSPACE(dest, bytes)        db__bzero(dest, bytes)
  913. #else
  914. #define DBZEROSPACE(dest, bytes)        MEMZERO(dest, bytes)
  915. #endif /* (VMS) */
  916.  
  917. /* These constants are used for RPC options. The first group are flags
  918.  * in a 2-byte bitmask, so they'll be different on Suns and Vaxes. The second
  919.  * group are flags in a 1-byte bitmask, so they should be machine-independent.
  920.  */
  921. #define DBRPCRECOMPILE    ((DBSMALLINT)1)
  922.  
  923. #define DBRPCRETURN    ((BYTE)1)
  924.  
  925. #if VMS
  926. /* These constants are used for VMS network manipulation. */
  927. #define    DB_IO_EVENT    1
  928. #define    DB_INTERRUPT_EVENT 2
  929. #define    DB_TIMER_EVENT    4
  930. #endif /* VMS */
  931.  
  932. /*
  933. ** Macros to set values in the LOGINREC structure.
  934. */
  935. #define    DBSETHOST    1
  936. #define    DBSETUSER    2
  937. #define    DBSETPWD    3
  938. #define    DBSETHID    4
  939. #define    DBSETAPP    5
  940. #define    DBSETBCP    6
  941. #define    DBSETLHOST(a,b)        dbsetlname((a), (b), DBSETHOST)
  942. #define    DBSETLUSER(a,b)        dbsetlname((a), (b), DBSETUSER)
  943. #define    DBSETLPWD(a,b)        dbsetlname((a), (b), DBSETPWD)
  944. #define    DBSETLHID(a,b)        dbsetlname((a), (b), DBSETHID)
  945. #define    DBSETLAPP(a,b)        dbsetlname((a), (b), DBSETAPP)
  946. #define    DBSETLHIER(a,b)        ((a)->lseclab.slhier = ((b) << 8) | ((b) >> 8) )
  947. #define    DBGETLHIER(a)  (((a)->lseclab.slhier << 8) | ((a)->lseclab.slhier >> 8))
  948. #define    DBSETLROLE(a,b)        ((a)->lrole = b)
  949. #define    DBGETLROLE(a)        ( (a)->lrole )
  950. #define    DBSETLCOMP(a,b)        dbbmove((BYTE*)(b), \
  951.                     (BYTE *) ((a)->lseclab.slcomp),\
  952.                     (DBINT) 8)
  953. #define    DBSETONECOMP(a,b)    (a)[ ((b)-1)/8 ] |= ( 0x80 >> (( (b)-1 ) % 8) )
  954. #define    DBUNSETONECOMP(a,b)    (a)[ ((b)-1)/8 ] &= ~( 0x80 >> (( (b)-1 ) % 8) )
  955. #define    DBGETONECOMP(a,b)    (a)[ ((b)-1)/8 ] & ( 0x80 >> (( (b)-1 ) % 8) )
  956.  
  957. extern DBBOOL            DbDebug;
  958. extern int    DbTime;
  959. extern DBBOOL            DbIntrFlag;    /* True if an interrupt was typed. */
  960. extern char    DbSeparator;
  961. extern int    DbHeader;
  962. extern int    DbTimeout;    /* default timeout value for DBPROCESSes. */
  963. extern DBUSMALLINT    Compatibility_Mask;
  964.  
  965. /* bcp functions */
  966. extern BCPDESC    *bcpinit();
  967. extern RETCODE    bcpcontrol();
  968. extern RETCODE    bcpcolumn();
  969. extern RETCODE    bcpformat();
  970. extern RETCODE    bcpexec();
  971. extern RETCODE    bcpbind();
  972. extern RETCODE    bcpsendrow();
  973. extern RETCODE    bcpabort();
  974. extern RETCODE    bcpcollen();
  975. extern DBINT    bcpdone();
  976.  
  977. /* DB-LIBRARY minor error numbers */
  978. #define SYBESYNC    20001    /* Read attempted while out of synchronization
  979.                  * with SQL Server.
  980.                  */
  981. #define SYBEFCON    20002    /* SQL Server connection failed. */
  982. #define SYBETIME    20003    /* SQL Server connection timed out. */
  983. #define SYBEREAD    20004    /* Read from SQL Server failed. */
  984. #define SYBEBUFL    20005    /* DB-LIBRARY internal error - send buffer
  985.                  * length corrupted.
  986.                  */
  987. #define SYBEWRIT    20006    /* Write to SQL Server failed. */
  988. #define SYBEVMS        20007    /* Sendflush: VMS I/O error. */
  989. #define SYBESOCK    20008    /* Unable to open socket */
  990. #define SYBECONN    20009    /* Unable to connect socket -- SQL Server is
  991.                  * unavailable or does not exist.
  992.                  */
  993. #define SYBEMEM        20010    /* Unable to allocate sufficient memory */
  994. #define SYBEDBPS    20011    /* Maximum number of DBPROCESSes
  995.                  * already allocated.
  996.                  */
  997. #define SYBEINTF    20012    /* Server name not found in interface file */
  998. #define SYBEUHST    20013    /* Unknown host machine name */
  999. #define SYBEPWD        20014    /* Incorrect password. */
  1000. #define    SYBEOPIN    20015    /* Could not open interface file. */
  1001. #define SYBEINLN    20016    /* Interface file: unexpected end-of-line. */
  1002. #define SYBESEOF    20017    /* Unexpected EOF from SQL Server. */
  1003. #define SYBESMSG    20018    /* General SQL Server error: Check messages
  1004.                  * from the SQL Server.
  1005.                  */
  1006. #define SYBERPND    20019    /* Attempt to initiate a new SQL Server
  1007.                  * operation with results pending.
  1008.                  */
  1009. #define SYBEBTOK    20020    /* Bad token from SQL Server: Data-stream
  1010.                  * processing out of sync.
  1011.                  */
  1012. #define SYBEITIM    20021    /* Illegal timeout value specified. */
  1013. #define SYBEOOB        20022    /* Error in sending out-of-band data to
  1014.                  * SQL Server.
  1015.                  */
  1016. #define SYBEBTYP    20023    /* Unknown bind type passed to DB-LIBRARY
  1017.                  * function.
  1018.                  */
  1019. #define    SYBEBNCR    20024    /* Attempt to bind user variable to a
  1020.                  * non-existent compute row.
  1021.                  */
  1022. #define SYBEIICL    20025    /* Illegal integer column length returned by
  1023.                  * SQL Server. Legal integer lengths are 1, 2,
  1024.                  * and 4 bytes.
  1025.                  */
  1026. #define SYBECNOR     20026    /* Column number out of range. */
  1027. #define SYBENPRM    20027    /* NULL parameter not allowed for this
  1028.                  * dboption.
  1029.                  */
  1030. #define SYBEUVDT     20028    /* Unknown variable-length datatype encountered.
  1031.                  */
  1032. #define SYBEUFDT     20029    /* Unknown fixed-length datatype encountered. */
  1033. #define SYBEWAID    20030    /* DB-LIBRARY internal error: ALTFMT following
  1034.                  * ALTNAME has wrong id.
  1035.                  */
  1036. #define SYBECDNS    20031    /* Datastream indicates that a compute column is
  1037.                  * derived from a non-existent select-list
  1038.                  * member.
  1039.                  */
  1040. #define SYBEABNC    20032    /* Attempt to bind to a non-existent column. */
  1041. #define SYBEABMT    20033    /* User attempted a dbbind() with mismatched
  1042.                  * column and variable types.
  1043.                  */
  1044. #define SYBEABNP    20034    /* Attempt to bind using NULL pointers. */
  1045. #define SYBEAAMT    20035    /* User attempted a dbaltbind() with mismatched
  1046.                  * column and variable types.
  1047.                  */
  1048. #define SYBENXID    20036    /* The Server did not grant us a
  1049.                  * distributed-transaction ID.
  1050.                  */
  1051. #define SYBERXID    20037    /* The Server did not recognize our
  1052.                  * distributed-transaction ID.
  1053.                  */
  1054. #define SYBEICN        20038    /* Invalid computeid or compute column number.
  1055.                  */
  1056. #define SYBENMOB    20039    /* No such member of 'order by' clause. */
  1057. #define SYBEAPUT    20040    /* Attempt to print unknown token. */
  1058. #define SYBEASNL    20041    /* Attempt to set fields in a null loginrec. */
  1059. #define SYBENTLL    20042    /* Name too long for loginrec field. */
  1060. #define SYBEASUL    20043    /* Attempt to set unknown loginrec field. */
  1061. #define SYBERDNR    20044    /* Attempt to retrieve data from a non-existent
  1062.                  * row.
  1063.                  */
  1064. #define SYBENSIP    20045    /* Negative starting index passed to dbstrcpy().
  1065.                  */
  1066. #define SYBEABNV    20046    /* Attempt to bind to a NULL program variable.
  1067.                  */
  1068. #define SYBEDDNE    20047    /* DBPROCESS is dead or not enabled. */
  1069. #define SYBECUFL    20048    /* Data-conversion resulted in underflow. */
  1070. #define SYBECOFL    20049    /* Data-conversion resulted in overflow. */
  1071. #define SYBECSYN    20050    /* Attempt to convert data stopped by syntax
  1072.                  * error in source field.
  1073.                  */
  1074. #define SYBECLPR    20051    /* Data-conversion resulted in loss of
  1075.                  * precision.
  1076.                  */
  1077. #define SYBECNOV    20052    /* Attempt to set variable to NULL resulted
  1078.                  * in overflow.
  1079.                  */
  1080. #define SYBERDCN    20053    /* Requested data-conversion does not exist. */
  1081. #define SYBESFOV    20054    /* dbsafestr() overflowed its destination
  1082.                  * buffer.
  1083.                  */
  1084. #define SYBEUNT        20055    /* Unknown network type found in
  1085.                  * interface file.
  1086.                  */
  1087. #define SYBECLOS    20056    /* Error in closing network connection. */
  1088. #define SYBEUAVE    20057    /* Unable to allocate VMS event flag. */
  1089. #define SYBEUSCT    20058    /* Unable to set communications timer. */
  1090. #define SYBEEQVA    20059    /* Error in queueing VMS AST routine. */
  1091. #define SYBEUDTY    20060    /* Unknown datatype encountered. */
  1092. #define SYBETSIT    20061    /* Attempt to call dbtsput() with an
  1093.                  * invalid timestamp.
  1094.                  */
  1095. #define SYBEAUTN    20062    /* Attempt to update the timestamp of a table
  1096.                  * which has no timestamp column.
  1097.                  */
  1098. #define SYBEBDIO    20063    /* Bad bulk-copy direction.  Must be either
  1099.                  * IN or OUT.
  1100.                  */
  1101. #define SYBEBCNT    20064    /* Attempt to use Bulk Copy with a non-existent
  1102.                  * Server table.
  1103.                  */
  1104. #define SYBEIFNB    20065    /* Illegal field number passed to bcp_control().
  1105.                  */
  1106. #define SYBETTS        20066    /* The table which bulk-copy is attempting to
  1107.                  * copy to a host-file is shorter than the
  1108.                  * number of rows which bulk-copy was instructed
  1109.                  * to skip.
  1110.                  */
  1111. #define SYBEKBCO    20067    /* 1000 rows successfully bulk-copied to
  1112.                  * host-file.
  1113.                  */
  1114. #define SYBEBBCI    20068    /* Batch successfully bulk-copied to SQL Server.
  1115.                  */
  1116. #define SYBEKBCI    20069    /* Bcp: 1000 rows sent to SQL Server. */
  1117. #define SYBEBCRE    20070    /* I/O error while reading bcp data-file. */
  1118. #define SYBETPTN    20071    /* Syntax error: only two periods are permitted
  1119.                  * in table names.
  1120.                  */
  1121. #define SYBEBCWE    20072    /* I/O error while writing bcp data-file. */
  1122. #define SYBEBCNN    20073    /* Attempt to bulk-copy a NULL value into
  1123.                  * Server column %d,  which does not accept
  1124.                  * NULL values.
  1125.                  */
  1126. #define SYBEBCOR    20074    /* Attempt to bulk-copy an oversized row to the
  1127.                  * SQL Server.
  1128.                  */
  1129. #define SYBEBCIS    20075    /* Attempt to bulk-copy an illegally-sized
  1130.                  * column value to the SQL Server.
  1131.                  */
  1132. #define SYBEBCPI    20076    /* bcp_init() must be called before any other
  1133.                  * bcp routines.
  1134.                  */
  1135. #define SYBEBCPN    20077    /* bcp_bind(), bcp_collen() and bcp_colptr()
  1136.                  * may be used only after bcp_init() has been
  1137.                  * called with the copy direction set to DB_IN.
  1138.                  */
  1139. #define SYBEBCPB    20078    /* bcp_bind() may NOT be used after bcp_init()
  1140.                  * has been passed a non-NULL input file name.
  1141.                  */
  1142. #define SYBEVDPT    20079    /* For bulk copy, all variable-length data
  1143.                  * must have either a length-prefix or a
  1144.                  * terminator specified.
  1145.                  */
  1146. #define SYBEBIVI    20080    /* bcp_columns() and bcp_colfmt() may be used
  1147.                  * only after bcp_init() has been passed a
  1148.                  * valid input file.
  1149.                  */
  1150. #define SYBEBCBC    20081    /* bcp_columns() must be called before
  1151.                  * bcp_colfmt().
  1152.                  */
  1153. #define SYBEBCFO    20082    /* Bcp host-files must contain at least one
  1154.                  * column.
  1155.                  */
  1156. #define SYBEBCVH    20083    /* bcp_exec() may be called only after
  1157.                  * bcp_init() has been passed a valid host file.
  1158.                  */
  1159. #define SYBEBCUO    20084    /* Bcp: Unable to open host data-file. */
  1160. #define SYBEBCUC    20085    /* Bcp: Unable to close host data-file. */
  1161. #define SYBEBUOE    20086    /* Bcp: Unable to open error-file. */
  1162. #define SYBEBUCE    20087    /* Bcp: Unable to close error-file. */
  1163. #define SYBEBWEF    20088    /* I/O error while writing bcp error-file. */
  1164. #define SYBEASTF    20089    /* VMS: Unable to setmode for control_c ast. */
  1165. #define    SYBEUACS    20090    /* VMS: Unable to assign channel to sys$command.
  1166.                  */
  1167. #define SYBEASEC    20091    /* Attempt to send an empty command buffer to
  1168.                  * the SQL Server.
  1169.                  */
  1170. #define SYBETMTD    20092    /* Attempt to send too much TEXT data via the
  1171.                  * dbmoretext() call.
  1172.                  */
  1173. #define SYBENTTN    20093    /* Attempt to use dbtxtsput() to put a new
  1174.                  * text-timestamp into a non-existent data row.
  1175.                  */
  1176. #define SYBEDNTI    20094    /* Attempt to use dbtxtsput() to put a new
  1177.                  * text-timestamp into a column whose datatype
  1178.                  * is neither SYBTEXT nor SYBIMAGE.
  1179.                  */
  1180. #define SYBEBTMT    20095    /* Attempt to send too much TEXT data via the
  1181.                  * bcp_moretext() call.
  1182.                  */
  1183. #define SYBEORPF    20096    /* Attempt to set remote password would
  1184.                  * overflow the login-record's remote-password
  1185.                  * field.
  1186.                  */
  1187. #define SYBEUVBF    20097    /* Attempt to read an unknown version of BCP
  1188.                  * format-file.
  1189.                  */
  1190. #define SYBEBUOF    20098    /* Bcp: Unable to open format-file. */
  1191. #define SYBEBUCF    20099    /* Bcp: Unable to close format-file. */
  1192. #define SYBEBRFF    20100    /* I/O error while reading bcp format-file. */
  1193. #define SYBEBWFF    20101    /* I/O error while writing bcp format-file. */
  1194. #define SYBEBUDF    20102    /* Bcp: Unrecognized datatype found in
  1195.                  * format-file.
  1196.                  */
  1197. #define SYBEBIHC    20103    /* Incorrect host-column number found in bcp
  1198.                  * format-file.
  1199.                  */
  1200. #define SYBEBEOF    20104    /* Unexpected EOF encountered in BCP data-file.
  1201.                  */
  1202. #define SYBEBCNL    20105    /* Negative length-prefix found in BCP
  1203.                  * data-file.
  1204.                  */
  1205. #define SYBEBCSI    20106    /* Host-file columns may be skipped only when
  1206.                  * copying INto the Server.
  1207.                  */
  1208. #define SYBEBCIT    20107    /* It's illegal to use BCP terminators with
  1209.                  * program variables other than
  1210.                  * SYBCHAR, SYBBINARY, SYBTEXT, or SYBIMAGE.
  1211.                  */
  1212. #define SYBEBCSA    20108    /* The BCP hostfile '%s' contains only %ld
  1213.                  * rows. Skipping all of these rows is not
  1214.                  * allowed.
  1215.                  */
  1216. #define SYBENULL    20109    /* NULL DBPROCESS pointer passed to DB-Library.
  1217.                  */
  1218. #define SYBEUNAM    20110    /* Unable to get current username from
  1219.                  * operating system.
  1220.                  */
  1221. #define SYBEBCRO    20111    /* The BCP hostfile '%s' contains only %ld
  1222.                  * rows. It was impossible to read the
  1223.                  * requested %ld rows.
  1224.                  */
  1225. #define SYBEMPLL    20112    /* Attempt to set maximum number of DBPROCESSes
  1226.                  * lower than 1.
  1227.                  */
  1228. #define SYBERPIL    20113    /* It is illegal to pass -1 to dbrpcparam()
  1229.                  * for the datalen of parameters which are of
  1230.                  * type SYBCHAR, SYBVARCHAR, SYBBINARY, or
  1231.                  * SYBVARBINARY.
  1232.                  */
  1233. #define SYBERPUL    20114    /* When passing a SYBINTN parameter via
  1234.                  * rpcparam(), it's necessary to specify the
  1235.                  * parameter's maximum or actual length, so
  1236.                  * that DB-Library can recognize it as a
  1237.                  * SYBINT1, SYBINT2, or SYBINT4.
  1238.                  */
  1239. #define SYBEUNOP    20115    /* Unknown option passed to dbsetopt(). */
  1240. #define SYBECRNC    20116    /* The current row is not a result of compute
  1241.                  * clause %d, so it is illegal to attempt to
  1242.                  * extract that data from this row.
  1243.                  */
  1244. #define    SYBERTCC    20117    /* dbreadtext() may not be used to receive
  1245.                  * the results of a query which contains a
  1246.                  * COMPUTE clause.
  1247.                  */
  1248. #define SYBERTSC    20118    /* dbreadtext() may only be used to receive
  1249.                  * the results of a query which contains a
  1250.                  * single result column.
  1251.                  */
  1252. #define SYBEUCRR    20119    /* Internal software error: Unknown
  1253.                  * connection result reported by                         * dbpasswd().
  1254.                  */
  1255. #define SYBERPNA    20120    /* The RPC facility is available only when
  1256.                  * using a SQL Server whose version number
  1257.                  * is 4.0 or greater.
  1258.                  */
  1259. #define SYBEOPNA    20121    /* The text/image facility is available only
  1260.                  * when using a SQL Server whose version number
  1261.                  * is 4.0 or greater.
  1262.                  */
  1263. #define SYBEFGTL    20122   /* Bcp: Row number for the first row to be 
  1264.                 ** copied cannot be greater than the row 
  1265.                 ** number for the last row to be copied.
  1266.                 */
  1267. #define SYBEACNV    20123    /* Attempt to do conversion with NULL 
  1268.                 ** destination variable.
  1269.                 */
  1270. #define SYBENTST        20124   /* The file being opened must be a stream_lf.
  1271.                 */
  1272.  
  1273. /* Forward declarations of DB-LIBRARY routines */
  1274.  
  1275. RETCODE        abort_xact();
  1276. void        close_commit();
  1277. RETCODE        commit_xact();
  1278.  
  1279. DBINT        bcp_batch();
  1280. RETCODE        bcp_bind();
  1281. RETCODE        bcp_colfmt();
  1282. RETCODE        bcp_collen();
  1283. RETCODE        bcp_colptr();
  1284. RETCODE        bcp_columns();
  1285. RETCODE        bcp_control();
  1286. DBINT        bcp_done();
  1287. RETCODE        bcp_exec();
  1288. RETCODE        bcp_init();
  1289. RETCODE        bcp_moretext();
  1290. RETCODE        bcp_sendrow();
  1291.  
  1292. int        datetochar();
  1293. BYTE        *dbadata();
  1294. DBINT        dbadlen();
  1295. int        dballcols();
  1296. RETCODE        dbaltbind();
  1297. int        dbaltcolid();
  1298. DBINT        dbaltlen();
  1299. char        *dbaltname();
  1300. int        dbaltop();
  1301. int        dbalttype();
  1302. RETCODE        dbbind();
  1303. BYTE        *dbbylist();
  1304. void        db__bzero();
  1305. RETCODE        dbcancel();
  1306. RETCODE        dbcanquery();
  1307. char        *dbchange();
  1308. void        dbclose();
  1309. void        dbclrbuf();
  1310. RETCODE        dbclropt();
  1311. RETCODE        dbcmd();
  1312. DBBOOL                dbcolbrowse();
  1313. DBINT        dbcollen();
  1314. char        *dbcolname();
  1315. char        *dbcolsource();
  1316. int        dbcoltype();
  1317. char        *dbcolufmt();
  1318. char        *dbcontrolcmd();
  1319. DBINT        dbconvert();
  1320. DBINT        (*dbcvtproc())();
  1321. BYTE        *dbdata();
  1322. DBINT        dbdatlen();
  1323. int        (*dberrhandle())();
  1324. int        dberrno();
  1325. char        *dberrstr();
  1326. void        dbexit();
  1327. RETCODE        dbfcmd();
  1328. void        dbfprhead();
  1329. void        dbfreebuf();
  1330. void        dbfreequal();
  1331. char        *dbgetchar();
  1332. int            dbgetmaxprocs();
  1333. char        *dbgetmsg();
  1334. int        dbgetoff();
  1335. STATUS        dbgetrow();
  1336. BYTE        *dbgetuserdata();
  1337. DBBOOL                dbhasretstat();
  1338. RETCODE        dbinit();
  1339. DBBOOL                dbisopt();
  1340. BYTE        *dbkeydata();
  1341. DBINT        dbkeydlen();
  1342. LOGINREC    *dblogin();
  1343. void        dbloginfree();
  1344. int        (*dbmsghandle())();
  1345. RETCODE        dbmoretext();
  1346. char        *dbname();
  1347. STATUS        dbnextrow();
  1348. int        dbnumalts();
  1349. int        dbnumcols();
  1350. int        dbnumcompute();
  1351. int        dbnumkeys();
  1352. int        dbnummsg();
  1353. int        dbnumrets();
  1354. DBPROCESS    *dbopen();
  1355. int        dbordercol();
  1356. char        *dboserrstr();
  1357. void        dbperror();
  1358. void        dbprhead();
  1359. RETCODE        dbprrow();
  1360. char        *dbprtype();
  1361. char        *dbqual();
  1362. DBINT        dbreadpage();
  1363. void        dbrecftos();
  1364. RETCODE        dbresults();
  1365. BYTE        *dbretdata();
  1366. DBINT        dbretlen();
  1367. char        *dbretname();
  1368. DBINT        dbretstatus();
  1369. int        dbrettype();
  1370. RETCODE        dbrpcinit();
  1371. RETCODE        dbrpcparam();
  1372. RETCODE        dbrpcsend();
  1373. void        dbrpwclr();
  1374. RETCODE        dbrpwset();
  1375. RETCODE        dbsafestr();
  1376. char        *dbservermsg();
  1377. void        dbsetavail();
  1378. void        dbsetbusy();
  1379. RETCODE        dbsetconnect();
  1380. void        dbsetidle();
  1381. void        dbsetifile();
  1382. void        dbsetinterrupt();
  1383. RETCODE        dbsetlbool();
  1384. RETCODE        dbsetlname();
  1385. RETCODE        dbsetlogintime();
  1386. RETCODE        dbsetmaxprocs();
  1387. DBBOOL                dbsetmsg();
  1388. RETCODE        dbsetnull();
  1389. RETCODE        dbsetopt();
  1390. RETCODE        dbsettime();
  1391. RETCODE        dbsettimeout();
  1392. RETCODE        dbsetufmt();
  1393. void        dbsetuserdata();
  1394. RETCODE        dbsqlexec();
  1395. RETCODE        dbsqlok();
  1396. RETCODE        dbsqlsend();
  1397. RETCODE        dbstrcpy();
  1398. int        dbstrlen();
  1399. DBBOOL                dbtabbrowse();
  1400. int        dbtabcount();
  1401. char        *dbtabname();
  1402. char        *dbtabsource();
  1403. DBBINARY    *dbtimestamp();
  1404. int        dbtslen();
  1405. char        *dbtsname();
  1406. int        dbtsnewlen();
  1407. DBBINARY    *dbtsnewval();
  1408. RETCODE        dbtsput();
  1409. RETCODE        dbtxplen();
  1410. DBBINARY    *dbtxptr();
  1411. DBBINARY    *dbtxtimestamp();
  1412. DBBINARY    *dbtxtsnewval();
  1413. RETCODE        dbtxtsput();
  1414. RETCODE        dbuse();
  1415. DBBOOL        dbvarylen();
  1416. DBBOOL                dbwillconvert();
  1417. RETCODE        dbwritepage();
  1418. RETCODE        dbwritetext();
  1419. char        *mnytochar();
  1420. DBPROCESS    *open_commit();
  1421. DBINT        start_xact();
  1422.  
  1423. /* VMS programs can use the AST facility to write asynchronous DB-LIBRARY
  1424.  * programs.
  1425.  */
  1426.  
  1427. #if VMS
  1428. extern RETCODE    dbcancel_a();
  1429. extern RETCODE    dbcanquery_a();
  1430. extern RETCODE    dbnextrow_a();
  1431. extern RETCODE    dbopen_a();
  1432. extern RETCODE    dbresults_a();
  1433. extern RETCODE    dbsqlexec_a();
  1434. extern RETCODE    dbsqlok_a();
  1435. #endif /* VMS */
  1436.